﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Parallelshanktwistarills1
    {
        public static void _Parallelshanktwistarills1(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);


            double scale = 10; //放大系数



            double d = 0.18 * scale;
            double l = 20 * scale;
            double l1 = 2.2 * scale;
            double l2 = 1.4 * scale;
            double d1 = 1 * scale;

            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + l/2 -15, v1.Y);
            Vector2 v38 = new Vector2(v1.X + 3, v1.Y);
            Vector2 v3 = new Vector2(v38.X + l2 / 19.48, v1.Y + d / 2);
            Vector2 v4 = new Vector2(v38.X + l2 / 13.3, v1.Y - d / 2);
            Vector2 v40 = new Vector2(v3.X + l2 / 3.812, v1.Y);
            Vector2 v5 = new Vector2(v40.X + l2 / 6.376, v40.Y - d / 2.047);
            Vector2 v39 = new Vector2(v38.X + l2 / 19.48 / 2, v1.Y + d / 4);
            Vector2 v7 = new Vector2(v39.X + l2 / 7.929, v39.Y - d / 2.28);
            Vector2 v8 = new Vector2(v40.X + l2 / 9.266 - l2 / 116.666, v40.Y - d / 2.948 - d / 90);
            Vector2 v9 = new Vector2(v7.X + l2 / 18.885 + l2 / 466.666, v7.Y - d / 6.577 + d / 45);
            Vector2 v10 = new Vector2(v3.X + l2 / 17.671 + l2 * 0.02, v3.Y - d / 14.87 + d / 45);
            Vector2 v11 = new Vector2(v10.X + l2 / 2.553, v10.Y - d / 1.576);
            Vector2 v6 = new Vector2(v11.X + l2 / 12.752, v11.Y - d / 3.42);
            Vector2 v12 = new Vector2(v11.X + l2 / 5.89, v11.Y - d / 2.391);
            Vector2 v14 = new Vector2(v10.X + l2 / 5.154 + l2 / 155.555, v10.Y - d / 21.375 + d / 90);
            Vector2 v15 = new Vector2(v14.X + l2 / 2.657, v14.Y - d / 1.91);
            Vector2 v13 = new Vector2(v15.X + l2 / 6.36 - l2 / 175, v15.Y - d / 2.206 - d / 180);
            Vector2 v17 = new Vector2(v14.X + l2 / 4.776 + l2 / 155.555, v14.Y - d * 0.0263 + d / 90);
            Vector2 v18 = new Vector2(v17.X + l2 / 3.217, v17.Y - d / 2.514);
            Vector2 v16 = new Vector2(v18.X + l2 / 6.778 - l2 / 87.5 - l2 / 127.2727, v18.Y - d / 1.858 - d / 60 - d / 90);
            Vector2 v19 = new Vector2(v38.X + l2, v18.Y - d / 1.628);
            Vector2 v20 = new Vector2(v17.X + l2 / 7.276 + l2 / 22.58, v17.Y - d * 0.041 + d * 0.03888);
            Vector2 v21 = new Vector2(v20.X + l2 / 4.193 - l2 / 22.58, v20.Y - d * 0.0467 - d * 0.03888);
            Vector2 v22 = new Vector2(v21.X + l2 / 23.788, v21.Y - d / 7.6);
            Vector2 v23 = new Vector2(v19.X, v22.Y - d / 14.869);
            Vector2 v24 = new Vector2(v23.X, v19.Y + d / 0.904);
            Vector2 v25 = new Vector2(v21.X - d / 17.18 - l2 / 73.684, v21.Y + d * 0.07-d*0.03333);
            Vector2 v26 = new Vector2(v38.X + l1, v24.Y);
            Vector2 v27 = new Vector2(v26.X, v19.Y);
            Vector2 v28 = new Vector2(v26.X + d1 / 0.869, v1.Y + d1 / 2);
            Vector2 v29 = new Vector2(v28.X + l2, v28.Y);
            Vector2 v30 = new Vector2(v29.X, v1.Y);
            Vector2 v31 = new Vector2(v29.X, v29.Y * -1);
            Vector2 v32 = new Vector2(v28.X, v31.Y);
            Vector2 v33 = new Vector2(v29.X + d1, v29.Y);
            Vector2 v34 = new Vector2(v33.X + l2 * 2, v33.Y);
            Vector2 v35 = new Vector2(v34.X, v34.Y * -1);
            Vector2 v36 = new Vector2(v33.X, v35.Y);
            Vector2 v37 = new Vector2(v33.X, v1.Y);

            Vector2 v41 = new Vector2(v2.X + l2, v2.Y);
            Vector2 v42 = new Vector2(v41.X - d1 / 2 - 3, v41.Y);
            Vector2 v43 = new Vector2(v41.X + d1 / 2 + 3, v41.Y);
            Vector2 v44 = new Vector2(v41.X, v41.Y + d1 / 2 + 3);
            Vector2 v45 = new Vector2(v41.X, v41.Y - d1 / 2 - 3);
            Vector2 v46 = fun.Polar(v41, -133 * pi / 180, d / 2);
            Vector2 v48 = fun.Polar(v41, 41 * pi / 180, d / 2);
            Vector2 v49 = fun.Polar(v41, 131 * pi / 180, d / 2);
            Vector2 v50 = fun.Polar(v41, -55 * pi / 180, d / 2);
            Vector2 v51 = new Vector2(v41.X - d / 31.666, v41.Y + d / 79.166);
            Vector2 v47 = new Vector2(v41.X + d / 25, v41.Y +  d / 29.6875);





            //作图
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v3));
            line2.Vertexes.Add(new LwPolylineVertex(v38));
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes[2].Bulge = Math.Tan(41 * pi / 180 / 4);
            fun.PolyFill(dxf, line2, 0.01, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v39));
            line3.Vertexes.Add(new LwPolylineVertex(v7));
            line3.Vertexes.Add(new LwPolylineVertex(v8));
            line3.Vertexes[0].Bulge = Math.Tan(1 * pi / 180 / 4);
            line3.Vertexes[1].Bulge = Math.Tan(32 * pi / 180 / 4);
            fun.PolyFill(dxf, line3, 0.01, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v3));
            line4.Vertexes.Add(new LwPolylineVertex(v40));
            line4.Vertexes.Add(new LwPolylineVertex(v5));
            line4.Vertexes.Add(new LwPolylineVertex(v6));
            line4.Vertexes[0].Bulge = Math.Tan(-26 * pi / 180 / 4);
            line4.Vertexes[1].Bulge = Math.Tan(15 * pi / 180 / 4);
            line4.Vertexes[2].Bulge = Math.Tan(45 * pi / 180 / 4);
            fun.PolyFill(dxf, line4, 0.01, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v10));
            line5.Vertexes.Add(new LwPolylineVertex(v11));
            line5.Vertexes.Add(new LwPolylineVertex(v12));
            line5.Vertexes.Add(new LwPolylineVertex(v13));
            line5.Vertexes[0].Bulge = Math.Tan(-41 * pi / 180 / 4);
            line5.Vertexes[1].Bulge = Math.Tan(33 * pi / 180 / 4);
            line5.Vertexes[2].Bulge = Math.Tan(15 * pi / 180 / 4);
            fun.PolyFill(dxf, line5, 0.01, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v14));
            line6.Vertexes.Add(new LwPolylineVertex(v15));
            line6.Vertexes.Add(new LwPolylineVertex(v16));
            line6.Vertexes[0].Bulge = Math.Tan(-43 * pi / 180 / 4);
            line6.Vertexes[1].Bulge = Math.Tan(43 * pi / 180 / 4);
            fun.PolyFill(dxf, line6, 0.01, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v17));
            line7.Vertexes.Add(new LwPolylineVertex(v18));
            line7.Vertexes.Add(new LwPolylineVertex(v19));
            line7.Vertexes[0].Bulge = Math.Tan(-43 * pi / 180 / 4);
            line7.Vertexes[1].Bulge = Math.Tan(17 * pi / 180 / 4);
            fun.PolyFill(dxf, line7, 0.01, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(v20));
            line8.Vertexes.Add(new LwPolylineVertex(v21));
            line8.Vertexes.Add(new LwPolylineVertex(v22));
            line8.Vertexes.Add(new LwPolylineVertex(v23));
            line8.Vertexes[0].Bulge = Math.Tan(-20 * pi / 180 / 4);
            line8.Vertexes[1].Bulge = Math.Tan(-23 * pi / 180 / 4);
            line8.Vertexes[2].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, line8, 0.01, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(v25));
            line9.Vertexes.Add(new LwPolylineVertex(v24));
            line9.Vertexes.Add(new LwPolylineVertex(v19));
            line9.Vertexes.Add(new LwPolylineVertex(v27));
            line9.Vertexes.Add(new LwPolylineVertex(v26));
            line9.Vertexes.Add(new LwPolylineVertex(v24));
            line9.Vertexes[0].Bulge = Math.Tan(-6 * pi / 180 / 4);
            fun.PolyFill(dxf, line9, 0.01, contour);

            LwPolyline line10 = new LwPolyline();
            line10.Vertexes.Add(new LwPolylineVertex(v26));
            line10.Vertexes.Add(new LwPolylineVertex(v28));
            line10.Vertexes.Add(new LwPolylineVertex(v29));
            line10.Vertexes.Add(new LwPolylineVertex(v30));
            line10.Vertexes.Add(new LwPolylineVertex(v31));
            line10.Vertexes.Add(new LwPolylineVertex(v30));
            line10.Vertexes[2].Bulge = Math.Tan(-60 * pi / 180 / 4);
            line10.Vertexes[3].Bulge = Math.Tan(60 * pi / 180 / 4);
            line10.Vertexes[4].Bulge = Math.Tan(60 * pi / 180 / 4);
            fun.PolyFill(dxf, line10, 0.01, contour);

            LwPolyline line11 = new LwPolyline();
            line11.Vertexes.Add(new LwPolylineVertex(v28));
            line11.Vertexes.Add(new LwPolylineVertex(v32));
            line11.Vertexes.Add(new LwPolylineVertex(v27));
            line11.Vertexes.Add(new LwPolylineVertex(v32));
            line11.Vertexes.Add(new LwPolylineVertex(v31));
            fun.PolyFill(dxf, line11, 0.01, contour);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v33));
            line12.Vertexes.Add(new LwPolylineVertex(v34));
            line12.Vertexes.Add(new LwPolylineVertex(v35));
            line12.Vertexes.Add(new LwPolylineVertex(v36));
            line12.Vertexes.Add(new LwPolylineVertex(v37));
            line12.Vertexes.Add(new LwPolylineVertex(v33));
            line12.Vertexes.Add(new LwPolylineVertex(v37));
            line12.Vertexes[3].Bulge = Math.Tan(-60 * pi / 180 / 4);
            line12.Vertexes[4].Bulge = Math.Tan(60 * pi / 180 / 4);
            line12.Vertexes[5].Bulge = Math.Tan(60 * pi / 180 / 4);
            fun.PolyFill(dxf, line12, 0.01, contour);

            Line line13 = new Line(v42, v43);
            line13.Layer = centre;
            line13.Linetype = Linetype.DashDot;
            line13.LinetypeScale = 3;
            dxf.AddEntity(line13);

            Line line14 = new Line(v44, v45);
            line14.Layer = centre;
            line14.Linetype = Linetype.DashDot;
            line14.LinetypeScale = 3;
            dxf.AddEntity(line14);

            fun.drawcircle(dxf, v41, d1 / 2, 0.1, contour);

            fun.drawcircle(dxf, v41, d / 2, 0.1, contour);

            LwPolyline line15 = new LwPolyline();
            line15.Vertexes.Add(new LwPolylineVertex(v46));
            line15.Vertexes.Add(new LwPolylineVertex(v51));
            line15.Vertexes.Add(new LwPolylineVertex(v47));
            line15.Vertexes.Add(new LwPolylineVertex(v48));
            line15.Vertexes[0].Bulge = Math.Tan(-62 * pi / 180 / 4);
            line15.Vertexes[2].Bulge = Math.Tan(43 * pi / 180 / 4);
            fun.PolyFill(dxf, line15, 0.01, contour);

            LwPolyline line16 = new LwPolyline();
            line16.Vertexes.Add(new LwPolylineVertex(v49));
            line16.Vertexes.Add(new LwPolylineVertex(v47));
            line16.Vertexes[0].Bulge = Math.Tan(-50 * pi / 180 / 4);
            fun.PolyFill(dxf, line16, 0.01, contour);

            LwPolyline line17 = new LwPolyline();
            line17.Vertexes.Add(new LwPolylineVertex(v51));
            line17.Vertexes.Add(new LwPolylineVertex(v50));
            line17.Vertexes[0].Bulge = Math.Tan(-47 * pi / 180 / 4);
            fun.PolyFill(dxf, line17, 0.01, contour);



            //标注

            double height = 5;
            double arrowsize = 1;
            double exline = 2;




            fun.dimrot1(dxf, v3, v4, 90, d1, 1, height, arrowsize, exline, "d=" + d, "", "");

            fun.dimrot1(dxf, v38, v19, 180, d1, 1, height, arrowsize, exline, "l2=" + l2, "", "");

            fun.dimrot1(dxf, v38, v27, 180, d1*2, 1, height, arrowsize, exline, "l1=" + l1, "", "");

            fun.dimrot1(dxf, v38, v35, 180, d1 * 3, 1, height, arrowsize, exline, "1=" + l, "", "");

            fun.dimrot1(dxf, v34, v35, -90, d1 / 2, 1, height, arrowsize, exline, "d1=" + d1, "", "");



            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}
